package com.hetongxue.configuration;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description: swagger配置
 * @ClassNmae: Swagger
 * @Author: 何同学
 * @DateTime: 2022-03-21 23:21
 **/
@Configuration(proxyBeanMethods = false)
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    /*
    通过127.0.0.1:8080/hetongxue/doc.com访问
    具体使用:https://blog.csdn.net/xiaojin21cen/article/details/78654652
     */

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("个人")//分组名称
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hetongxue.controller")) //配置控制器扫面包路径
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("博客文档")
                .description("何同学博客接口信息")
                .termsOfServiceUrl("服务条款地址")
                .version("v1.0")
                .license("v1.0")
                .licenseUrl("https://gitee.com/hale459")
                .contact(new Contact("何同学", "https://blog.csdn.net/qq_14818715", "yhe.cq@qq.com"))
                .build();
    }

}
